-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change net to operator #2846
change net to operator #2846
Conversation
paddle/framework/net.h
Outdated
* @brief Add an Operator according to `def`. | ||
*/ | ||
virtual OpIndex AddOp(const OpProto &def) = 0; | ||
virtual void AddOp(const OpDesc& def) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to make OpCreator
returns a std::shared_ptr<OpBase>
, and we could alias it to OpPtr
.
AddOp
should take a OpPtr
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
paddle/framework/net.h
Outdated
|
||
/** | ||
* @brief Add optimizer operators acctording to `attrs`. | ||
*/ | ||
virtual void AddOptimizerOps(const OpAttrs &attrs) = 0; | ||
virtual void AddOptimizerOps() = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AddOperatorOps
and AddBackwardOps
is not a member function of Network.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
paddle/framework/net.h
Outdated
|
||
private: | ||
// the operators owned by `Network`. | ||
std::vector<Operator> ops_; | ||
std::vector<std::unique_ptr<OperatorBase>> ops_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::shared_ptr is better.
The std::shared_ptr
is the only pointer can expose to Python correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
paddle/framework/net.cc
Outdated
PlainNet::PlainNet(const NetDesc& def) {} | ||
void PlainNet::AddOp(const OpDesc& desc) { | ||
std::unique_ptr<OperatorBase> op(OpRegistry::CreateOp(desc)); | ||
ops_.push_back(std::move(op)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emplace_back is better.
emplace_back vs push_back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will take a look~~
paddle/framework/net.h
Outdated
OpIndex AddOp(const std::string &type, const std::vector<std::string> &inputs, | ||
const std::vector<std::string> &outputs, | ||
const OpAttrs &attrs = OpAttrs()); | ||
void AddBackwardOps() override {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we decided to net = Backward(net)
. return net composed by gradient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -103,18 +79,10 @@ class Net { | |||
class PlainNet : public Net { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we have reached an agreement in treating net as a composed Op, seems we do not need a PlainNet
anymore. We can have two types of Net, Net
, DAGNet
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think net will have a common interface AddOp
, so I add the net base interface with only AddOp
* OperatorBase should not store OpDesc, because not All op contains an OpDesc and not all ops create from OpDesc. * Networks do not contain OpDesc, and do not created by OpDesc * Do not register Network to OpRegistry. * The network is directly created by user in Python. Not from registry. * Correctly handle the `inputs` and `outputs` of a Network. * Add CompleteAddOp() methods * Remove `AddOp(OpDesc&)`. All op are added by pointer. * Rewrite unit test for truely tested what networks do. * Remove `DemoOp` and `DemoOpTest` because it is useless and break the CI
Refine NetOp
paddle/framework/operator_test.cc
Outdated
@@ -1,135 +0,0 @@ | |||
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this file should not be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, except @jacquesqiao should review this PR, too.
fix: #2857
review: #2851 first